import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/pages/daily_work_report_module/his_daily_module/his_daily_controller.dart';
import 'package:app/pages/daily_work_report_module/my_daily_module/my_daily_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import '../../../common/app_theme.dart';
import '../../../common/colors.dart';
import '../../../common/tool.dart';
import '../../../components/nodata_page.dart';
import '../my_daily_module/my_daily_model.dart';
import '../top_dialog_page.dart';
import '../../../services/address.dart';

class HisDailyView extends GetView{

  HisDailyController controller = Get.put(HisDailyController());

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: BaseAppBar(preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
      child: Text('他人日报'),),
      // AppBar(
      //   leading: IconButton(
      //     onPressed: () {
      //       Get.back();
      //     },
      //     icon: Image.asset(
      //       'images/leftarr.png',
      //       color: Colors.white,
      //       width: 15,
      //       height: 15,
      //     ),
      //   ),
      //   title: Text('他人日报'),
      //   backgroundColor: AppColor.themeColor,
      // ),
      body:GetBuilder<HisDailyController>(builder: (_){
        return Container(
          child:  Column(
            children: [
              Container(
                color: Colors.white,
                height: 45,
                child:   Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(left: 15),
                      child:  Row(
                        children: [
                          GestureDetector(
                            child: Text('所有',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 13),),
                            onTap: ()=>controller.topClick(),
                          ),
                          // controller.isTopShow==false?Image.asset('images/arrow-down.png',width: 12,height: 12,
                          // ):Image.asset('images/arrow-up.png',width: 12,height: 12,color: AppColor.themeColor,)
                        ],
                      ),
                    ),
                    Container(
                        decoration: BoxDecoration(
                            color: AppColor.bgColor,
                            borderRadius: BorderRadius.all(Radius.circular(13))
                        ),
                        width: Get.width-100,
                        alignment: Alignment.centerLeft,
                        margin: EdgeInsets.only(top: 0,left: 10,right: 10),
                        padding: EdgeInsets.only(left: 15),
                        height: 30,
                        child: Row(
                          children: [
                            Icon(Icons.search,size: 20,color: AppColor.smallTextColor,),
                            Container(
                              alignment: Alignment.center,
                              color: Colors.transparent,
                              width: Get.width-150,
                              height: 30,
                              child: TextField(
                                controller: controller.editingController,
                                onChanged: (values){
                                  print(values);
                                  controller.requestDataWithHis(search: values);
                                },
                                decoration: InputDecoration(
                                    isCollapsed: true,
                                    border: InputBorder.none,
                                    hintText: '请输入关键词',hintStyle: TextStyle(
                                    color: AppColor.hintColor,fontSize: 13
                                )
                                ),
                                style: TextStyle(color: AppColor.smallTextColor, fontSize: 14),
                              ),
                            )
                          ],
                        )
                    ),
                  ],
                ),
              ),
              Expanded(child:  Container(
                padding: EdgeInsets.only(top: 5),
                color: AppColor.bgColor,
                child: EasyRefresh.custom(
                  // header: MaterialHeader(),
                  emptyWidget: controller.dataArr.isNotEmpty
                      ? null
                      : Container(
                    height: Get.height,
                    color: Colors.red,
                    child: NoDataPage(),
                  ),
                  onRefresh: ()=>controller.pullToData(),

                  slivers: [
                    SliverList(delegate: _mySliverChildBuilderDelegate(),),
                  ],
                ),
              )),
            ],
          ),
        );
      }),
    );
  }

  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
          (BuildContext context, int index) {
        MyDailyItemModel _model = controller.dataArr[index];
        return GestureDetector(
          onTap: (){
            // Get.to(MyDailyDetailPage(_model.id));
            Get.toNamed('/myDailyDetailDetail',arguments: '${_model.id}');

          },
          child: Container(
            // margin: EdgeInsets.all(5),
            // height: 10,
            margin: EdgeInsets.only(top: 5),
            padding: EdgeInsets.only(left: 15),
            color: Colors.white,
            child:Row(
              children: [
                CircleAvatar(
                  radius: 20,
                  backgroundImage: NetworkImage(
                      '${Address.homeHost}${_model.headerImg}'
                  ),
                  // child: Image.network('${Address.homeHost}${_model.headerImg}'),
                ),
                Container(
                  margin: EdgeInsets.only(left: 5,),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        margin: EdgeInsets.only(top: 10),
                        color: Colors.white,
                        width: Get.width-80,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text('${_model.author}',style: appThemeData.textTheme.bodyText1,),
                            Text('${_model.createDate}',style: appThemeData.textTheme.bodyText1!.
                            copyWith(color: AppColor.themeColor,fontSize: 10),)
                          ],
                        ),
                      ),
                      SizedBox(height: 3,),
                      Text('${_model.teamName}',style: appThemeData.textTheme.subtitle1?.copyWith(fontSize: 11),),
                      SizedBox(height: 3,),
                      Text('${_model.dateBeauty}',style: appThemeData.textTheme.subtitle1?.copyWith(fontSize: 11),),
                      SizedBox(height: 3,),
                    ],
                  ),
                )
              ],
            ),
          ),
        );
      },
      childCount: controller.dataArr.length,
    );
  }

}